package PlaneTest;

import java.awt.*;

//炮弹类
public class Shell extends GameObject{
    //炮弹沿着指定的角度生成
    double degree;
    public Shell(){
        x = 200;
        y = 200;
        degree = Math.random()*Math.PI*2;

        width = 5;
        height = 5;
        speed = 20;


    }

    @Override
    public void drowMyself(Graphics g) {
//        super.drowMyself(g);
        Color c = g.getColor();
        g.setColor(Color.yellow);
        g.fillOval((int)x,(int)y,width,height);

        g.setColor(c);

        //根据自己的算法指定一定的路径
        x += speed*Math.cos(degree);
        y += speed*Math.sin(degree);
        //碰到边界改变方向
        if (y > Constant.gameHeight-this.height || y<40){
            degree = -degree;
        }
        if (x > Constant.gameWidth-this.width || x<0){
            degree = Math.PI - degree;
        }


    }
}
